﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web;

namespace gnet1WCFServices
{
  // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
  public class Service1 : IService1
  {
    private string path;
    //private readonly string path = HttpContext.Current.Server.MapPath("~/test/pagecounter.txt");
    public string GetData(int value)
    {
      return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
      if (composite == null)
      {
        throw new ArgumentNullException("composite");
      }
      if (composite.BoolValue)
      {
        composite.StringValue += "Suffix";
      }
      return composite;
    }

    public string GetSiteCounter()
    {
      try
      {
        string path = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + "../test/pagecounter.txt";

        if (File.Exists(path))
        {
          string value1 = File.ReadAllText(path);
          return value1;
        }
        return "0";
      }
      catch (Exception ex)
      {
        return ex.Message;
      }
    }

    public string GetPushButtonCounter()
    {
      return "100";
    }
  }
}
